package com.longcai.cm.moudules.system.controller;

import com.longcai.cm.base.bean.PageVo;
import com.longcai.cm.base.controller.BaseController;
import com.longcai.cm.base.bean.Pageable;
import com.longcai.cm.bean.R;
import com.longcai.cm.common.utils.RequestUtil;
import com.longcai.cm.common.utils.StringUtils;
import com.longcai.cm.moudules.system.domain.SysLog;
import com.longcai.cm.moudules.system.service.SysLogService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * 【系统模块】====>【日志管理】
 *
 * @author chenyue
 * @Description: TODO
 * @file:
 * @throws @date
 * 2018/11/20 17:31
 */
@RestController
@RequestMapping("/sysLog")
@Api(value = "系统管理-日志", tags = "系统管理-日志")
@ApiSort(7)
public class SysLogController extends BaseController {

    @Resource
    private SysLogService sysLogService;


    /**
     * 【API】====>【系统模块】====>【日志模块】===>获取日志数据
     *
     * @param request [请求信息]
     * @return R
     */

    @ResponseBody
    @PostMapping(value = "/getList")
    @ApiOperation(value = "【S7001】获取操作日志列表", notes = "获取操作日志列表")
    @ApiOperationSupport(order = 1)
    public R<PageVo<SysLog>> querySysLog(HttpServletRequest request) {
        Pageable pageInfo = RequestUtil.getPageable(request);
        Map<String, Boolean> map = new HashMap<>();
        map.put("create_time", false);
        pageInfo.setPageOrderParam(map);
        PageVo<SysLog> result = sysLogService.getPageBean(pageInfo, SysLog.class);
        return R.success(result);
    }

    /**
     * 【API】====>【系统模块】====>【日志模块】===>删除日志数据
     *
     * @param id
     * @return
     */
    @PostMapping("/remove/{id}")
    @ResponseBody
    @ApiOperation(value = "【S7002】删除操作日志", notes = "删除操作日志")
    @ApiOperationSupport(order = 2)
    public R remove(@PathVariable("id") String id) {
        if (StringUtils.isEmpty(id)) {
            return R.error("缺少必要参数");
        }
        this.sysLogService.removeById(id);
        return R.success();
    }

}
